<?php /* Smarty version 2.6.26, created on 2011-02-27 15:06:20
         compiled from admin/product_manage.html */ ?>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "admin/header.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
<div class="container">
	<div class="floattop">
		<div class="itemtitle">
			<h3>产品管理</h3>
			<ul class="tab1">
				<li><a href="product_manage.php"><span>产品列表</span></a></li>
				<li><a href="?act=show_add_form"><span>添加产品</span></a></li>
			</ul>
		</div>
	</div>
	<div class="floattopempty"></div>

	<?php if ($this->_tpl_vars['show_add_form']): ?>		
		<form id="formadd" action="?act=add" method="post" enctype="multipart/form-data">
			<table class="tb tb2">
				<tbody>

					<tr>
						<td class="td27" colspan="2">产品名称：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="text" value="" name="product_name">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">产品描述：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<textarea id="editor"  class="xheditor-mfull" style="width:80%;diaplay:none;" cols="80" rows="50"  name="product_description"></textarea>
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">产品图片：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="file" type="file" value="" name="product_images">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">推荐：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="radio" type="radio" value="0" name="recommend" checked>&nbsp;&nbsp;否&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="radio" type="radio" value="1" name="recommend">&nbsp;&nbsp;是
						</td>
						<td class="vtop tips2"></td>
					</tr>										
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	<?php elseif ($this->_tpl_vars['show_edit_form']): ?>
		<form id="formedit" action="?act=save" method="post" enctype="multipart/form-data">
			<table class="tb tb2">
				<tbody>

					<tr>
						<td class="td27" colspan="2">产品名称：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="text" name="product_name" value="<?php echo $this->_tpl_vars['products']['product_name']; ?>
">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">产品描述：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<textarea id="editor"  class="xheditor-mfull" style="width:80%;diaplay:none;" cols="80" rows="50"  name="product_description" value="<?php echo $this->_tpl_vars['products']['product_description']; ?>
"></textarea>
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">产品图片：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="file" type="file" value="" name="product_images"><br />
							<?php if ($this->_tpl_vars['products']['product_images'] != ''): ?><div class="product-img"><img src="../upload/<?php echo $this->_tpl_vars['products']['product_images']; ?>
" /><a href="#" class="del-img"> 删除图片</a></div><?php endif; ?>
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td class="td27" colspan="2">推荐：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="radio" type="radio" value="0" name="recommend" <?php if ($this->_tpl_vars['products']['recommend'] == 0): ?>checked<?php endif; ?>>&nbsp;&nbsp;否&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input class="radio" type="radio" value="1" name="recommend" <?php if ($this->_tpl_vars['products']['recommend'] == 1): ?>checked<?php endif; ?>>&nbsp;&nbsp;是
						</td>
						<td class="vtop tips2"></td>
					</tr>						
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		<input type="hidden" name="product_id" value="<?php echo $this->_tpl_vars['products']['product_id']; ?>
">	
		<input type="hidden" name="o_product_name" id="o_product_name" value="<?php echo $this->_tpl_vars['products']['product_name']; ?>
">
		<input type="hidden" name="o_product_images"  value="<?php echo $this->_tpl_vars['products']['product_images']; ?>
">		
		</form>		
		
	<?php else: ?>
		<div class="list-div">
		<table class="tb tb2" cellspacing="1" cellpadding="3">
			<tbody>
				<tr class="header">
					<th>产品编号</th>
					<th>产品名称</th>
					<th>产品图片</th>
					<th>推荐</th>
					<th>操作</th>
				</tr>
				<?php $_from = $this->_tpl_vars['product_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }if (count($_from)):
    foreach ($_from as $this->_tpl_vars['pl']):
?>
				<tr class="td-cls">
					<td><?php echo $this->_tpl_vars['pl']['product_id']; ?>
</td>
					<td><?php echo $this->_tpl_vars['pl']['product_name']; ?>
</td>
					<td><img src="../upload/<?php echo $this->_tpl_vars['pl']['product_images']; ?>
" /></td>
					<td class="recommend <?php if ($this->_tpl_vars['pl']['recommend'] == 0): ?>no<?php else: ?>yes<?php endif; ?>">&nbsp;</td>
					<td><span class="operation"><a href="?act=edit&product_id=<?php echo $this->_tpl_vars['pl']['product_id']; ?>
">编辑</a></span><span class="operation"><a href="#" rel="<?php echo $this->_tpl_vars['pl']['product_id']; ?>
" class="del">删除</a></span></td>
				</tr>
				<?php endforeach; endif; unset($_from); ?>
				<tr><td colspan="8" class="pagenavigator"><?php echo $this->_tpl_vars['pagenavigator']; ?>
</td></tr>
			</tbody>
		</table>	
	</div>
	<?php endif; ?>
<script type="text/javascript" src="../editor/xheditor.js"></script>	
<script type="text/javascript">
$(document).ready(function(){
$('#editor').xheditor();
	$('#formadd, #formedit').validate({
		rules: {
			/*cate_id: {required: true},*/
			product_name: {
				required: true,
				remote: {
					url:'product_manage.php',
					data: {
						act:'checkExist',
						o_product_name:function(){return $("#o_product_name").val()}
					}				
				}
			},
			product_description: {required: true},
			product_images: {accept:'gif|jpg|png'}
		},
		errorPlacement: function(error, element) {
			error.appendTo(element.parent());
		},	
		messages: {
			/*cate_id: {required: '请选择产品类别'},*/
			product_name: {required: '请输入产品名称', remote:'此产品名称已存在'},
			product_description: {required: '请输入产品描述'},
			product_images:{accept:'图片格式不正确，请选择gif|jpg|png格式图片'}
		},
		success:function(label) { 
			label.html(" ").addClass("right");
		}
		
	});
});

$(".del").click(function(){
	if(confirm('删除后不能恢复，确认删除？')) {
		var obj = $(this);
		var product_id = obj.parents('tr').find('td').eq(0).text();
		$.get('product_manage.php', {act:'del', product_id:product_id}, function(data){ 
			if(data == 1) {
				alert('删除成功');
				obj.parents('tr').remove();	
			}
		});
	}
});

$(".del-img").click(function() { 
	if(confirm('删除后不能恢复，确认删除？')) {
		var obj = $(this);
		var product_id = $("input[name='product_id']").val();
		$.get('product_manage.php', {act:'del_img', product_id:product_id}, function(data){ 
			if(data == 1) {
				alert('删除成功');
				obj.parents(".product-img").remove();	
			}
		});
	}	
});

$(".recommend").click(function() { 
	var state = $(this).attr('class').split(' ');
	var product_id = $(this).parents('tr').find('td').eq(0).text();
	var recommend = '';
	$(this).removeClass();
	if(state[1] == 'no') {
		$(this).addClass("recommend yes");
		recommend = 1;
	}
	if(state[1] == 'yes') {
		$(this).addClass("recommend no");
		recommend = 0;
	}
	$.get("product_manage.php", {act:'recommend', product_id:product_id, recommend:recommend});
});
</script>	
</div>
<?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => "admin/footer.html", 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>